package widgets

import (
	"fmt"

	g "github.com/AllenDang/giu"
)

func (app *MyApp) ParamsRows() []*g.TableRowWidget {
	res := []*g.TableRowWidget{}
	for i, v := range app.paramsPairs {
		idx := i
		res = append(res, g.TableRow(
			g.Label(v.K),
			g.Label(v.V),
			g.Row(
				g.Button("修改").OnClick(func() {
					app.changerIdx = idx
					app.changerValue = ""
					g.OpenPopup("change-param" + fmt.Sprintf("%d", idx))
				}),
				g.PopupModal("change-param"+fmt.Sprintf("%d", idx)).Layout(
					g.InputText(&app.changerValue),
					g.Row(
						g.Button("Yes").OnClick(func() {
							app.paramsPairs[app.changerIdx].V = app.changerValue
							g.CloseCurrentPopup()
						}),
						g.Button("No").OnClick(func() {
							g.CloseCurrentPopup()
						}),
					),
				),
				g.Button("删除").OnClick(func() {
					app.paramsPairs = append(app.paramsPairs[:idx], app.paramsPairs[idx+1:]...)
				}),
			),
		))
	}
	return res
}
